package com.itext.pdf;

import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;

import com.itextpdf.text.BadElementException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.PdfWriter;

public class ImagesMerge2Pdf {
	String[] IMAGES={"d:/tif/page_1.jpg","d:/tif/page_2.jpg","d:/tif/page_3.jpg","d:/tif/page_4.jpg"};
	public static void main(String[] args) throws MalformedURLException, IOException, DocumentException {
		String pdf="d:/tif/Images2Pdf.pdf";
		new ImagesMerge2Pdf().createPdf(pdf);
	}
	
	public void createPdf(String dest) throws MalformedURLException, IOException, DocumentException{
		Image image=Image.getInstance(IMAGES[0]);
		Document document=new Document(image);
		PdfWriter.getInstance(document, new FileOutputStream(dest));
		document.open();
		for (String imagePath : IMAGES) {
			image=Image.getInstance(imagePath);
			document.setPageSize(image);
			document.newPage();
			document.add(image);
		}
		document.close();
		
	}
}
